package com.lebang.medicalInquiry.service;


import cn.hutool.core.convert.Convert;

import com.lebang.medicalInquiry.mapper.SysDictDataMapper;
import com.lebang.medicalInquiry.model.po.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @version V1.0
 */
@Service
public class SysDictDataService {
    @Resource
    private SysDictDataMapper dictDataMapper;

    /**
     * 根据条件分页查询字典数据
     *
     * @return 字典数据集合信息
     */

    public List<SysDictData> selectDictDataList(String dictType,
                                                String dictLabel,
                                                Integer status, Integer page, Integer limit) {
        return dictDataMapper.selectDictDataList(dictType, dictLabel, status, page, limit);
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     *
     * @param dictType  字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */

    public String selectDictLabel(String dictType, String dictValue) {
        return dictDataMapper.selectDictLabel(dictType, dictValue);
    }

    /**
     * 根据字典数据ID查询信息
     *
     * @param dictCode 字典数据ID
     * @return 字典数据
     */

    public SysDictData selectDictDataById(Long dictCode) {
        return dictDataMapper.selectDictDataById(dictCode);
    }

    /**
     * 批量删除字典数据
     *
     * @param ids 需要删除的数据
     * @return 结果
     */

    public int deleteDictDataByIds(String ids) {

        return dictDataMapper.deleteDictDataByIds(Convert.toStrArray(ids));
    }

    /**
     * 新增保存字典数据信息
     *
     * @param dictData 字典数据信息
     * @return 结果
     */

    public int insertDictData(SysDictData dictData) {
        dictData.setCreateTime(LocalDateTime.now());
        return dictDataMapper.insertDictData(dictData);
    }

    /**
     * 修改保存字典数据信息
     *
     * @param dictData 字典数据信息
     * @return 结果
     */

    public int updateDictData(SysDictData dictData) {
        return dictDataMapper.updateDictData(dictData);
    }

    public int countDataList(String dictType,
                             String dictLabel,
                             Integer status) {
        return dictDataMapper.countDictDataList(dictType, dictLabel, status);
    }

    public List<SysDictData> selectBydictType(String dictType) {
        return dictDataMapper.selectDictDataByType(dictType);
    }
}
